package org.cainiao.basic.spring;

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.FileSystemResource;

public class SpringTest {

    public static void main(String[] args) {
        test1();
        test2();
    }

    private static void test1() {
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        // populate the factory with bean definitions

        // now register any needed BeanPostProcessor instances
        factory.addBeanPostProcessor(new AutowiredAnnotationBeanPostProcessor());
        factory.addBeanPostProcessor(new MyBeanPostProcessor());

        // now start using the factory
    }

    private static void test2() {
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        reader.loadBeanDefinitions(new FileSystemResource("beans.xml"));

        // bring in some property values from a Properties file
        PropertySourcesPlaceholderConfigurer cfg = new PropertySourcesPlaceholderConfigurer();
        cfg.setLocation(new FileSystemResource("jdbc.properties"));

        // now actually do the replacement
        cfg.postProcessBeanFactory(factory);
    }
}
